﻿layui.use('layer', function () {
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;

    ///添加
    var list = {
        deliveryName: '',
        deliveryNumber: '',
        deliveryDate: '',
        orderNumber: '',
        remark: '',
        finishedProductName: '',
        finishedProductNumber: '',
        specification: '',
        unit: '',
        productionNumber: '',
        outboundQuantity: '',
        warehouseName: '',
        dateTime: '',
        warehousePerson: '',
        addTime: '',
        addName: ''
    };
    form.on('submit(demo-ddd)', function (data) {
        list.deliveryName = $("#deliveryName").val();
        list.deliveryNumber = $("#deliveryNumber").val();
        list.deliveryDate = $("#deliveryDate").val();
        list.orderNumber = $("#orderNumber").val();
        list.remark = $("#remark").val();
        list.finishedProductName = $("#finishedProductName").val();
        list.finishedProductNumber = $("#finishedProductNumber").val();
        list.unit = $("#unit").val();
        list.specification = $("#specification").val();
        list.productionNumber = $("#productionNumber").val();
        list.outboundQuantity = $("#outboundQuantity").val();
        list.warehouseName = $("#warehouseName").val();
        list.dateTime = $("#dateTime").val();
        list.warehousePerson = $("#warehousePerson").val();
        console.log(list);
        $.ajax({
            url: '/Delivery/DeliveryUpdate',
            type: 'post',
            data: { data: JSON.stringify(list), token: localStorage.getItem("token") },
            success: function (res) {
                var s = JSON.parse(res)
                console.log(res)
                if (s.data >= 1) {
                    layer.alert("修改成功");
                    setTimeout(function () {
                        window.location.href = "/Delivery/DeliveryShowView";
                    }, 2000);
                }
                else {
                    layer.alert("修改失败");
                }
            }
        })
        return false; // 阻止默认 form 跳转

    })
    $(function () {
        Show();
    })
    function Show() {
        $.ajax({
            url: '/Delivery/DeliveryModel',
            type: 'get',
            data: { deliveryId: localStorage.getItem("deliveryId"), token: localStorage.getItem("token") },
            success: function (res) {
                var s = JSON.parse(res)
                console.log(s);
                $(s.data).each(function () {
                    $('#deliveryName').val(this.deliveryName)
                    $('#deliveryNumber').val(this.deliveryNumber)
                    $('#deliveryDate').val(this.deliveryDate.substring(0, 10))
                    $('#orderNumber').val(this.orderNumber)
                    $('#remark').val(this.remark)
                    $('#finishedProductName').val(this.finishedProductName)
                    $('#finishedProductNumber').val(this.finishedProductNumber)
                    $('#specification').val(this.specification)
                    $('#unit').val(this.unit)
                    $('#productionNumber').val(this.productionNumber)
                    $('#outboundQuantity').val(this.outboundQuantity)
                    $('#warehouseName').val(this.warehouseName)
                    $('#dateTime').val(this.dateTime.substring(0, 10))
                    $('#warehousePerson').val(this.warehousePerson)
                    list.deliveryName = this.deliveryName
                    list.deliveryId = this.deliveryId
                    list.deliveryDate = this.deliveryDate
                    list.deliveryNumber = this.deliveryNumber
                    list.orderNumber = this.orderNumber
                    list.remark = this.remark
                    list.finishedProductName = this.finishedProductName
                    list.specification = this.specification
                    list.unit = this.unit
                    list.productionNumber = this.productionNumber
                    list.outboundQuantity = this.outboundQuantity
                    list.warehouseName = this.warehouseName
                    list.dateTime = this.dateTime
                    list.warehousePerson = this.warehousePerson
                    list.addTime = this.addTime 
                    list.addName = this.addName
                    form.render('select');
                })
            }
        })
    }
});
